package com.rt.generalframework.core.util;


import java.math.BigDecimal;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.regex.Pattern;
import org.apache.commons.lang3.StringUtils;

public class DateUtil {

	public static void main(String[] args) {
		System.out.println(DateUtil.addSecond("16:48:00",1));
	}

	public static final SimpleDateFormat yMdSdf = new SimpleDateFormat("yyyyMMdd");
	/**
	 * yyyy-MM
	 */
	public static final String MONTH = "yyyy-MM";
	/**
	 * yyyy-MM-dd
	 */
	public static final String DATE = "yyyy-MM-dd";
	/**
	 * yyyy.MM.dd
	 */
	public static final String DATE_SIMPLE = "yyyy.MM.dd";
	/**
	 * MM-dd HH:mm
	 */
	public static final String DATE_MM_DD = "MM-dd HH:mm";
	/**
	 * MM年dd日 HH:mm
	 */
	public static final String DATE_MM_DD_CN = "M月d日 HH:mm";

	/**
	 *
	 */
	public static final String DATETIME = "yyyy-MM-dd HH:mm:ss";
	/**
	 *
	 */
	public static final String FULL_DATETIME = "yyyyMMddHHmmssSSS";
	/**
	 *
	 */
	public static final String MSEC = "yyyy-MM-dd HH:mm:ss.SSS";
	/**
	 * 无间隔日期格式 yyyyMMddHHmmss
	 */
	public static final String NOSPLIT_MDHM_DATETIME = "yyyyMMddHHmmss";

	/**
	 * 常规日期时间格式，24小时制yyyy-MM-dd HH:mm:ss
	 */
	public static final String NORMAL_DATETIME_FORMAT = "yyyy-MM-dd HH:mm:ss";
	/**
	 * 常规日期时间格式，24小时制yyyy年MM月dd日 HH时mm分
	 */
	public static final String NORMAL_DATETIME_FORMAT_CN = "yyyy年MM月dd日 HH时mm分";

	public static final String NORMAL_DATETIME_FORMAT_SIMPLE_CN = "yyyy年MM月dd日 HH:mm";

	public static final String NORMAL_DATETIME_FORMAT_SECOND_CN = "yyyy年MM月dd日 HH:mm:ss";
	/**
	 * 常规日期时间格式，24小时制yyyy年MM月dd日
	 */
	public static final String NORMAL_DATE_FORMAT_CN = "yyyy年MM月dd日";
	/**
	 * 常规日期时间格式，24小时制yyyy年M月d日 不要0
	 */
	public static final String NORMAL_DATE_FORMAT_CN_SIMPLE = "yyyy年M月d日";
	/**
	 * 常规日期时间格式，24小时制MM月dd日 HH时mm分
	 */
	public static final String NORMAL_MONTHDATETIME_FORMAT_CN = "MM月dd日 HH时mm分";
	/**
	 * 常规日期时间格式，MM月dd日
	 */
	public static final String NORMAL_MONTHDATE_FORMAT_CN = "MM月dd日";
	/**
	 * 常规日期时间格式，M月d日
	 */
	public static final String NORMAL_MONTHDATE_FORMAT_CN_SIMPLE = "M月d日";

	/**
	 * 常规日期时间格式，24小时制yyyy-MM-dd HH:mm 没有秒
	 */
	public static final String NORMAL_DATETIME_FORMAT_NO_SECOND = "yyyy-MM-dd HH:mm";

	/**
	 * yyyy-MM-dd HH
	 */
	public static final String NORMAL_DATETIME_FORMAT_HOUR = "yyyy-MM-dd HH";

	/** 常规日期，yyyy-MM-dd **/
	public static final String NORMAL_DATE_FORMAT = "yyyy-MM-dd";

	/**
	 * 无间隔日期格式，yyyyMMddHHmmssS
	 */
	public static final String NOSPLIT_DATE_FORMAT = "yyyyMMddHHmmssS";

	/**
	 * 斜杠间隔日期格式，yyyy/MM/dd HH:mm
	 */
	public static final String SLASHPLIT_DATE_FORMAT = "yyyy/MM/dd HH:mm";

	/**
	 * 24小时制格式
	 */
	public static final String TIME_FORMAT = "HH:mm";

	/**
	 * 截取时分秒
	 */
	public static final String TIME_MINUTE_SECOND_FORMAT = "HH:mm:ss";

	/**
	 * yyyy-MM-dd HH:mm:ss java.util.Locale.CHINA
	 */
	public static final DateFormat DATE_TIME_FORMAT = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss",Locale.CHINA);

	/**
     * 精确到毫秒的完整时间    如：yyyy-MM-dd HH:mm:ss.S
     */
    public static String FORMAT_FULL = "yyyy-MM-dd HH:mm:ss.S";

    /** 锁对象 */
    private static final Object LOCKOBJ = new Object();

    /** 存放不同的日期模板格式的sdf的Map */
    private static Map<String, ThreadLocal<SimpleDateFormat>> SDFMAP = new HashMap<String, ThreadLocal<SimpleDateFormat>>();

    /**
     * 返回一个ThreadLocal的sdf,每个线程只会new一次sdf
     *
     * @param pattern
     * @return
     */
    private static SimpleDateFormat getDateFormat(final String pattern) {
        ThreadLocal<SimpleDateFormat> tl = SDFMAP.get(pattern);
        // 此处的双重判断和同步是为了防止sdfMap这个单例被多次put重复的sdf
        if (tl == null) {
            synchronized (LOCKOBJ) {
                tl = SDFMAP.get(pattern);
                if (tl == null) {
                    // 只有Map中还没有这个pattern的sdf才会生成新的sdf并放入map
                    //System.out.println("put new sdf of pattern " + pattern + " to map");
                    // 这里是关键,使用ThreadLocal<SimpleDateFormat>替代原来直接new SimpleDateFormat
                    tl = new ThreadLocal<SimpleDateFormat>() {
                        @Override
                        protected SimpleDateFormat initialValue() {
                            //System.out.println("thread: " + Thread.currentThread() + " init pattern: " + pattern);
                            return new SimpleDateFormat(pattern);
                        }
                    };
                    SDFMAP.put(pattern, tl);
                }
            }
        }
        return tl.get();
    }

    /**
     * @Title: formatNew
     * @Description: 返回格式化时间
     * @author: lilsh  lilsh@corp.21cn.com
     * @date: 2014-9-15 下午4:45:35
     */
	public static String formatNew(Date date, String dateFormat) {
		return getDateFormat(dateFormat).format(date);
	}

	 /**
     * @Title: formatNew
     * @Description: 返回格式化时间
     * @author: lilsh  lilsh@corp.21cn.com
     * @date: 2014-9-15 下午4:45:35
     */
	public static String formatNew(Object date, String dateFormat) {
		return getDateFormat(dateFormat).format(date);
	}

	/**
     * @Title: parse
     * @Description: 返回解析时间
     * @author: lilsh  lilsh@corp.21cn.com
     * @date: 2014-9-15 下午4:45:35
     */
	public static Date parse(String strDate, String dateFormat) throws ParseException {
		return getDateFormat(dateFormat).parse(strDate);
	}


	/*
	 * 获取当前时间戳,格式:yyyy-MM-dd HH:mm:ss,时区为:东八区(GMT+8)
	 *
	 * @return
	 */
	public static String getCurrentTimestampStr(String sdf, String tz) {
		DateFormat df = new SimpleDateFormat(sdf);
		df.setTimeZone(TimeZone.getTimeZone(tz));
		return df.format(new Date());
	}

	/*
	 * 将日期转化成指定格式字符串
	 */
	public static String getDateStr(Date d, String sdf) {

		DateFormat df = new SimpleDateFormat(sdf);
		return df.format(d);
	}

	/*
	 * 获得输入日期的前后日期
	 */
	public static String addDateStr(Date d, int days, String sdf) {
		Calendar c = Calendar.getInstance();
		c.setTime(d);
		c.add(Calendar.DAY_OF_YEAR, days);
		DateFormat df = new SimpleDateFormat(sdf);
		return df.format(c.getTime());
	}

	public static String getDateEndTimeStr(Date d, int days) {
		Calendar c2 = Calendar.getInstance();
		c2.setTime(d);
		c2.set(Calendar.HOUR_OF_DAY, 23);
		c2.set(Calendar.MINUTE, 59);
		c2.set(Calendar.SECOND, 59);
		c2.add(Calendar.DAY_OF_YEAR, days);
		return format(c2.getTime(),NORMAL_DATETIME_FORMAT);
	}

	public static String getDateStartTimeStr(Date d, int days) {
		Calendar c2 = Calendar.getInstance();
		c2.setTime(d);
		c2.set(Calendar.HOUR_OF_DAY, 0);
		c2.set(Calendar.MINUTE, 0);
		c2.set(Calendar.SECOND, 0);
		c2.add(Calendar.DAY_OF_YEAR, days);
		return format(c2.getTime(),NORMAL_DATETIME_FORMAT);
	}

	/**
	 *
	 * @author:caoshanshan(caoshsh@corp.2cn.com)) description:在原有时间上增加或减少n个小时
	 * @params: String
	 */
	public static String getDateByAddHour(Date d, int hour) {
		Calendar c2 = Calendar.getInstance();
		c2.setTime(d);
		c2.add(Calendar.HOUR, hour);
		return format(c2.getTime(),NORMAL_DATETIME_FORMAT);
	}

	/**
	 * @param d
	 * @return 返回当前日期的开始时间
	 * @description
	 */
	public static Date getDateStartTime(Date d, int days) {
		Calendar c1 = Calendar.getInstance();
		c1.setTime(d);
		c1.set(Calendar.HOUR_OF_DAY, 0);
		c1.set(Calendar.MINUTE, 0);
		c1.set(Calendar.SECOND, 0);
		c1.add(Calendar.DAY_OF_YEAR, days);
		return c1.getTime();
	}

	/**
	 * @param d
	 * @return 返回当前日期的结束时间
	 * @description ...
	 */
	public static Date getDateEndTime(Date d, int days) {
		Calendar c2 = Calendar.getInstance();
		c2.setTime(d);
		c2.set(Calendar.HOUR_OF_DAY, 23);
		c2.set(Calendar.MINUTE, 59);
		c2.set(Calendar.SECOND, 59);
		c2.add(Calendar.DAY_OF_YEAR, days);
		return c2.getTime();
	}

	public static Date getFirstDayOfMonth(Date d) {
		Calendar c2 = Calendar.getInstance();
		c2.setTime(d);
		c2.set(Calendar.DAY_OF_MONTH, 1);
		c2.set(Calendar.HOUR_OF_DAY, 0);
		c2.set(Calendar.MINUTE, 0);
		c2.set(Calendar.SECOND, 0);
		return c2.getTime();
	}

	public static Date getLastDayOfMonth(Date d) {
		Calendar c2 = Calendar.getInstance();
		c2.setTime(d);
		c2.set(Calendar.DAY_OF_MONTH, c2
				.getActualMaximum(Calendar.DAY_OF_MONTH));
		c2.set(Calendar.HOUR_OF_DAY, 23);
		c2.set(Calendar.MINUTE, 59);
		c2.set(Calendar.SECOND, 59);
		return c2.getTime();
	}

	public static Date addDate(Date d, int days) {
		Calendar c = Calendar.getInstance();
		c.setTime(d);
		c.add(Calendar.DAY_OF_YEAR, days);
		return c.getTime();
	}

	/**
	 * 获取date下一天0点的时间
	 * @param date
	 * @return
	 */
	public static Date addDateDay(Date date, int day) {
		Calendar cal = Calendar.getInstance();
		cal.setTime(date);
		cal.set(Calendar.HOUR_OF_DAY, 0);
		cal.set(Calendar.MINUTE, 0);
		cal.set(Calendar.SECOND, 0);
		cal.set(Calendar.MILLISECOND, 0);
		cal.add(Calendar.DAY_OF_YEAR, day);
		return  cal.getTime();
	}

	public static int getDayOfDate(Date d) {
		Calendar c = Calendar.getInstance();
		c.setTime(d);
		return c.get(Calendar.DAY_OF_MONTH);
	}



	public static boolean isNumeric1(String str) {
		Pattern pattern = Pattern.compile("[0-9]*");
		return pattern.matcher(str).matches();
	}

	/**
	 * @author:caoshanshan(caoshsh@corp.2cn.com)) description:讲日期字符串转换为日期格式
	 * @throws ParseException
	 * @params: Date
	 */
	public static Date parseDateIgnoreCase(String dateStr) throws ParseException {
		if (dateStr == null || "".equalsIgnoreCase(dateStr)) {
			return null;
		} else {
			return parse(dateStr, NORMAL_DATE_FORMAT);
		}
	}

	public static Date parseDate(String dateStr, String type) throws Exception {
		if (dateStr == null || "".equalsIgnoreCase(dateStr)) {
			return null;
		} else {
			SimpleDateFormat dateFormat = new SimpleDateFormat(type);
			return dateFormat.parse(dateStr);
		}
	}

	public static Date parseDateV2(String dateStr, String type) {
		if (StringUtils.isBlank(dateStr)) {
			return null;
		}

		SimpleDateFormat dateFormat = getDateFormat(type);

		try {
			return dateFormat.parse(dateStr);
		} catch (ParseException e) {
			return null;
		}
	}

	public static String format(Date date, String fmt) {
		DateFormat formatter = new SimpleDateFormat(fmt);
		return formatter.format(date);
	}
	/**
	 *
	 * @Title: format
	 * @Description: yyyy-MM-dd
	 * @param date
	 * @return    设定文件
	 * @return String    返回类型
	 * @throws
	 */
	public static String format(Date date) {
		if(date == null){
			return "";
		}
		return format(date, NORMAL_DATE_FORMAT);
	}
	/**
	 *
	 * @Title: formatCurrentDate
	 * @Description: yyyy-MM-dd
	 * @return    设定文件
	 * @return String    返回类型
	 * @throws
	 */
	public static String formatCurrentDate() {
		return format(new Date(), NORMAL_DATE_FORMAT);
	}
	/**
	 *
	 * @Title: formatDateTime
	 * @Description: yyyy-MM-dd HH:mm:ss
	 * @param date
	 * @return    设定文件
	 * @return String    返回类型
	 * @throws
	 */
	public static String formatDateTime(Date date) {
		return format(date, NORMAL_DATETIME_FORMAT);
	}

	public static String formatCurrentDateTime() {
		return format(new Date(System.currentTimeMillis()),NORMAL_DATETIME_FORMAT);
	}

	// 获取当前时间戳 从1970年到当前的毫秒数
	public static long getTimeInMillis() {
		Calendar calendar = Calendar.getInstance();
		TimeZone tz = TimeZone.getTimeZone("GMT");
		calendar.setTimeZone(tz);
		return calendar.getTimeInMillis();// 本次提交当前时间戳。长整型，是从1970年到当前的毫秒数。
	}

	public static Date getNow() {
		return new Date(System.currentTimeMillis());
	}

	// 获取某一天所在那一年的第一天
	public static Date getFirstDayOfYear(Date date) {
		Calendar cal = Calendar.getInstance();
		cal.setTime(date);
		cal.set(Calendar.DAY_OF_YEAR, cal
				.getActualMinimum(Calendar.DAY_OF_YEAR));
		return getToday(cal.getTime());
	}
	// 获取某一天所在那一年的最后一天
		public static Date getLastDayOfYear(Date date) {
			Calendar cal = Calendar.getInstance();
			cal.setTime(date);
			cal.set(Calendar.DAY_OF_YEAR, cal
					.getActualMaximum(Calendar.DAY_OF_YEAR));
			return getTodayLast(cal.getTime());
		}
	// 得到今天凌晨的时间.
	public static Date getToday() {
		Calendar cal = Calendar.getInstance();
		cal.set(Calendar.HOUR_OF_DAY, 0);
		cal.set(Calendar.MINUTE, 0);
		cal.set(Calendar.SECOND, 0);
		cal.set(Calendar.MILLISECOND, 0);
		return cal.getTime();
	}

	// 得到今日23：59 时间
	public static Date getTodayLast() {
		Calendar cal = Calendar.getInstance();
		cal.set(Calendar.HOUR_OF_DAY, 23);
		cal.set(Calendar.MINUTE, 59);
		cal.set(Calendar.SECOND, 59);
		cal.set(Calendar.MILLISECOND, 999);
		return cal.getTime();
	}

	// 得到某一天的凌晨时间
	public static Date getToday(Date date) {
		Calendar cal = Calendar.getInstance();
		cal.setTime(date);
		cal.set(Calendar.HOUR_OF_DAY, 0);
		cal.set(Calendar.MINUTE, 0);
		cal.set(Calendar.SECOND, 0);
		cal.set(Calendar.MILLISECOND, 0);
		return cal.getTime();
	}


	// 得到某一天的23：59 时间
	public static Date getTodayLast(Date date) {
		Calendar cal = Calendar.getInstance();
		cal.setTime(date);
		cal.set(Calendar.HOUR_OF_DAY, 23);
		cal.set(Calendar.MINUTE, 59);
		cal.set(Calendar.SECOND, 59);
		cal.set(Calendar.MILLISECOND, 999);
		return cal.getTime();
	}

	// 得到几天前当天时间===================================================================
	public static Date getSomeDate(Date date, int dayNum) {
		Calendar cal = Calendar.getInstance();
		long DAY = 1000 * 3600 * 24;
		cal.setTimeInMillis(date.getTime() + DAY * (long) dayNum);
		return cal.getTime();
	}

	// 得到几月前当天时间===================================================================
	public static Date getSomeMonthDate(Date date, int monthNum) {
		Calendar cal = Calendar.getInstance();
		cal.setTime(date);
		cal.set(Calendar.MONTH, cal.get(Calendar.MONTH) + monthNum);
		return cal.getTime();
	}

	// 得到24小时内某小时的开始时间
	public static Date getSubsectionHourBegin(Date date, int sub) {
		Calendar cal = Calendar.getInstance();
		cal.setTime(date);
		cal.set(Calendar.HOUR_OF_DAY, sub);
		cal.set(Calendar.MINUTE, 0);
		cal.set(Calendar.SECOND, 0);
		cal.set(Calendar.MILLISECOND, 0);
		return cal.getTime();
	}

	// 得到24小时内某小时的末尾时间
	public static Date getSubsectionHourEnd(Date date, int sub) {
		Calendar cal = Calendar.getInstance();
		cal.setTime(date);
		cal.set(Calendar.HOUR_OF_DAY, sub);
		cal.set(Calendar.MINUTE, 59);
		cal.set(Calendar.SECOND, 59);
		cal.set(Calendar.MILLISECOND, 999);
		return cal.getTime();
	}

	public static Date getTheDay(Date date) {
		Calendar cal = Calendar.getInstance();
		cal.setTime(date);
		cal.set(Calendar.HOUR_OF_DAY, 0);
		cal.set(Calendar.MINUTE, 0);
		cal.set(Calendar.SECOND, 0);
		cal.set(Calendar.MILLISECOND, 0);
		return cal.getTime();
	}

	public static int getYear(Date date) {
		Calendar cld = Calendar.getInstance();
		cld.setTime(date);
		return cld.get(Calendar.YEAR);
	}

	// 返回的月数是 自然月-1 也就是说返回的月是从 0--11
	public static int getMonth(Date date) {
		Calendar cld = Calendar.getInstance();
		cld.setTime(date);
		return cld.get(Calendar.MONTH);
	}

	public static int getDate(Date date) {
		Calendar cld = Calendar.getInstance();
		cld.setTime(date);
		return cld.get(Calendar.DAY_OF_MONTH);
	}

	public static int getHour(Date date) {
		Calendar cld = Calendar.getInstance();
		cld.setTime(date);
		return cld.get(Calendar.HOUR_OF_DAY);
	}

	public static int getMin(Date date) {
		Calendar cld = Calendar.getInstance();
		cld.setTime(date);
		return cld.get(Calendar.MINUTE);
	}

	// 得到这个星期开始的时间,星期的开始从getFirstDayOfWeek()得到
	public static Date getThisWeekStart() {
		Calendar cal = Calendar.getInstance();
		cal.add(Calendar.DATE, -(cal.get(Calendar.DAY_OF_WEEK) - 1));
		return getTheDay(cal.getTime());
	}

	// 本月的开始
	public static Date getThisMonthStart() {
		Calendar cal = Calendar.getInstance();
		cal.set(Calendar.DAY_OF_MONTH, 1);
		return getTheDay(cal.getTime());
	}

	// 本月的开始
	public static Date getMonthStart(Date date) {
		Calendar cal = Calendar.getInstance();
		cal.setTime(date);
		cal.set(Calendar.DAY_OF_MONTH, 1);
		return getTheDay(cal.getTime());
	}

	public static Date getTheMonthStart(int amount) {
		Calendar cal = Calendar.getInstance();
		cal.setTime(getThisMonthStart());
		cal.add(Calendar.MONTH, amount);
		return cal.getTime();
	}

	// 本月的结束
	public static Date getThisMonthEnd() {
		Calendar cal = Calendar.getInstance();
		cal.set(Calendar.DATE, cal.getActualMaximum(Calendar.DAY_OF_MONTH));
		return getTodayLast(cal.getTime());
	}
	// 本月的结束
	public static Date getMonthEnd(Date date) {
		Calendar cal = Calendar.getInstance();
		cal.setTime(date);
		cal.set(Calendar.DATE, cal.getActualMaximum(Calendar.DAY_OF_MONTH));
		return getTodayLast(cal.getTime());
	}

	//当月天数
	public static int getMonthDay(Date date){
		Calendar cal = Calendar.getInstance();
		cal.setTime(date);
		return cal.getActualMaximum(Calendar.DAY_OF_MONTH);
	}


	// n分钟前或后 + -
	public static Date addMinute(Date date, int minute) {
		Calendar cal = Calendar.getInstance();
		cal.setTime(date);
		cal.add(Calendar.MINUTE, minute);
		return new Date(cal.getTime().getTime());
	}

	// n秒前或后 + -
	public static Date addSecond(Date date, int second) {
			Calendar cal = Calendar.getInstance();
			cal.setTime(date);
			cal.add(Calendar.SECOND, second);
			return new Date(cal.getTime().getTime());
	}
	public static String addSecond(String time, int second) {
		SimpleDateFormat format = new SimpleDateFormat("HH:mm:ss");
		Date date = null;
		try {
			date = format.parse(time);
		} catch (ParseException e) {
			e.printStackTrace();
		}
		Calendar cal = Calendar.getInstance();
		cal.setTime(date);
		cal.add(Calendar.SECOND, second);
		return format.format(cal.getTime());
	}
	// n小时前或后 + -
	public static Date addHour(Date date, int hour) {
		Calendar cal = Calendar.getInstance();
		cal.setTime(date);
		cal.add(Calendar.HOUR, hour);
		return new Date(cal.getTime().getTime());
	}

	// n天前或后 + -
	public static Date addDay(Date date, int day) {
		Calendar cal = Calendar.getInstance();
		cal.setTime(date);
		cal.add(Calendar.DATE, day);

		return new Date(cal.getTime().getTime());
	}

	// n月前或后 + -
	public static Date addMonth(Date date, int month) {
		Calendar cal = Calendar.getInstance();
		cal.setTime(date);
		cal.add(Calendar.MONTH, month);

		return new Date(cal.getTime().getTime());
	}

	// n年前或后 + -
	public static Date addYear(Date date, int year) {
		Calendar cal = Calendar.getInstance();
		cal.setTime(date);
		cal.add(Calendar.YEAR, year);

		return new Date(cal.getTime().getTime());
	}

	// 计算两个日期之间的天数
	public static int getDays(Date date1, Date date2) {
		int days = 0;
		days = (int) (Math.abs((date2.getTime() - date1.getTime())) / (24 * 60 * 60 * 1000));
		return days;
	}

	public static int getSecond(Date date1, Date date2) {
		int second = 0;
		second = (int) (Math.abs((date1.getTime() - date2.getTime()) / 1000));
		return second;
	}

	public static int getMinute(Date date1, Date date2) {
		int minute = 0;
		minute = (int) (Math.abs((date1.getTime() - date2.getTime())
				/ (60 * 1000)));
		return minute;
	}

	public static int getCompareMinute(Date date1, Date date2) {
		int minute = 0;
		minute = (int) ((date1.getTime() - date2.getTime()) / (60 * 1000));
		return minute;
	}

	public static int getCompareDate(Date date1, Date date2) {
		int date = 0;
		date = (int) ((date1.getTime() - date2.getTime()) / (24 * 3600 * 1000));
		return date;
	}

	// 计算两个日期之间的时间差(天、小时、分) 详细到秒 返回类型为String
	public static String getDayDif(Date date1, Date date2) {
		long DAY = 24 * 60 * 60 * 1000;
		long between = Math.abs((date2.getTime() - date1.getTime()));
		long day = between / DAY;
		long hour = (between / (60 * 60 * 1000) - day * 24);
		long min = ((between / (60 * 1000)) - day * 24 * 60 - hour * 60);
		long s = (between / 1000 - day * 24 * 60 * 60 - hour * 60 * 60 - min * 60);

		StringBuilder sb = new StringBuilder();
		if(day > 0)
			sb.append(day).append("天");
		if(hour > 0)
			sb.append(hour).append("小时");
		if(min > 0)
			sb.append(min).append("分");
		if(s > 0)
			sb.append(s).append("秒");
		return sb.toString();
	}

	public static Date[] getMonthStartAndEnd(String dateStr) throws Exception{
		Date[] date = new Date[2];
		if(StringUtils.isNotBlank(dateStr)){
			Date datePar = parseDate(dateStr, "yyyy-MM-dd");
			date [0]=getFirstDayOfMonth(datePar);
			date [1]=getLastDayOfMonth(datePar);
		}
		return date;
	}

	/**
	 * 取得表示当天的时间对象
	 *
	 * @return
	 */
	public static Date getCurrentDay() {
		Calendar ca = Calendar.getInstance();
		ca.set(Calendar.HOUR_OF_DAY, 0);
		ca.set(Calendar.MINUTE, 0);
		ca.set(Calendar.SECOND, 0);
		ca.set(Calendar.MILLISECOND, 0);
		return ca.getTime();
	}

	public static long getDayOfHour(long time) {
		Calendar ca = Calendar.getInstance();
		ca.setTimeInMillis(time);
		ca.set(Calendar.MINUTE, 0);
		ca.set(Calendar.SECOND, 0);
		ca.set(Calendar.MILLISECOND, 0);
		return ca.getTimeInMillis();
	}

	public static long addDayOfHour(long time, int hour) {
		Calendar ca = Calendar.getInstance();
		ca.setTimeInMillis(time);
		ca.add(Calendar.HOUR_OF_DAY, hour);
		return ca.getTimeInMillis();
	}

	/**
	 * 解析简单格式的日期yyyy-MM-dd HH:mm字符串
	 * @param simpleDateStr
	 * @return
	 */
	public static Date parseSimpleForMinute(String simpleDateStr) {
		if (StringUtils.isBlank(simpleDateStr))
			return null;
		try {
			DateFormat simpleDateFormatForMinute = new SimpleDateFormat("yyyy-MM-dd HH:mm");
			return simpleDateFormatForMinute.parse(simpleDateStr);
		} catch (ParseException e) {
			return null;
		}
	}

	/**
	 * 返回某个时间的"yyyy-MM-dd HH:mm"字符串
	 * @param time
	 * @return
	 */
	public static String getTimeStringForMinute(Long time) {
		DateFormat simpleDateFormatForMinute = new SimpleDateFormat("yyyy-MM-dd HH:mm");
		return simpleDateFormatForMinute.format(new Date(time));
	}

	public static String getDateStringForMinute(Date date) {
		DateFormat simpleDateFormatForMinute = new SimpleDateFormat("yyyy-MM-dd HH:mm");
		return simpleDateFormatForMinute.format(date);
	}

	/**
	 * 返回某个时间的"yyyy年MM日dd日 HH:mm:ss"字符串
	 * @param time
	 * @return
	 */
	public static String getTimeForSecondCN(Long time) {
		DateFormat simpleDateFormatForMinute = new SimpleDateFormat(NORMAL_DATETIME_FORMAT_SECOND_CN);
		return simpleDateFormatForMinute.format(new Date(time));
	}

	/**
	 * 解析简单格式yyyy-MM-dd HH:mm:ss的日期字符串
	 * @param simpleDateStr
	 * @return
	 */
	public static Date parseSimple(String simpleDateStr) {
		DateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		if (null == simpleDateStr)
			return null;
		try {
			return simpleDateFormat.parse(simpleDateStr);
		} catch (ParseException e) {
			return null;
		}
	}

	public static Date parseByPattern(String simpleDateStr, String pattern) {
		DateFormat simpleDateFormat = new SimpleDateFormat(pattern);
		if (null == simpleDateStr)
			return null;
		try {
			return simpleDateFormat.parse(simpleDateStr);
		} catch (ParseException e) {
			return null;
		}
	}

	/**
	 * 返回某个时间的"yyyy-MM-dd HH:mm:ss"字符串
	 * @param time
	 * @return
	 */
	public static String getTimeString(Long time) {
		final DateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		return simpleDateFormat.format(new Date(time));
	}

	public static String getTimeString(Long time,String fmt) {
		final DateFormat simpleDateFormat = new SimpleDateFormat(fmt);
		return simpleDateFormat.format(new Date(time));
	}

	/**
	 * 返回日期的微秒数
	 * @param date
	 * @return
	 */
	public static Long getTimeLong(Date date) {
		return date.getTime();
	}


	/**
	 * 获取当前的时间
	 *
	 * @return
	 */
	public static String formatCurrentTime(String patten) {
		return formatDateToString(new Date(), patten);
	}

	/**
	 * 将时间按格式转换为字符串，日期为空时转换为空字符串
	 *
	 * @param date
	 * @param patten
	 * @return
	 */
	public static String formatDateToString(Date date, String patten) {
		if (null == date)
			return "";
		SimpleDateFormat sd = new SimpleDateFormat(patten);
		return sd.format(date);
	}
	/**
     * Description:             把日期转换为字符串
     * @param date
     * @return yyyy-MM-dd HH:mm:ss
     */
    public static String dateToString(Date date) {
        if (date == null) {
            return "";
        }
        return dateToString(date, null);
    }
    /**
     * Description: 把日期转换为字符串
     * @param date
     * @param format default:yyyy-MM-dd HH:mm:ss
     * @return default:yyyy-MM-dd HH:mm:ss
     */
    public static String dateToString(Date date, String format) {
        if (date == null) {
            return "";
        }
        if (StringUtils.isBlank(format)) {
            return DATE_TIME_FORMAT.format(date);
        } else {
            return format(date,format);
        }
    }

	/**
	 * 将时间按24小时制格式("yyyy-MM-dd HH:mm:ss")转换为字符串，日期为空时转换为空字符串
	 *
	 * @param date
	 * @return
	 */
	public static String formatDateNormal(Date date) {
		if (null == date)
			return "";
		return format(date,NORMAL_DATETIME_FORMAT);
	}

	/**
	 * 将时间按24小时制格式("yyyy-MM-dd HH:mm:ss")转换为字符串，日期为空时转换为空字符串
	 *
	 * @param date
	 * @return
	 */
	public static String formatDateNormal(Long date) {
		if (null == date)
			return "";
		return format(new Date(date),NORMAL_DATETIME_FORMAT);
	}

	/**
	 * 功能描述：将字符串按格式转换为时间，字符串为空时转换为null
	 *
	 * @param dateStr 时间字符串
	 * @param patten 格式
	 * @return
	 * @version 1.0.0
	 * @since 1.0.0 create on: 2012-5-2
	 */
	public static Date formatStrToDate(String dateStr, String patten) {
		if (StringUtils.isBlank(dateStr)){
			return null;
		}
		try {
			return parse(dateStr,patten);
		} catch (ParseException e) {
			return null;
		}
	}

	/**
	 * 将字符串按24小时制格式("yyyy-MM-dd HH:mm:ss")转换为时间
	 * @param dateStr 时间字符串
	 * @return 转换成的时间，字符串为空时转换为null
	 */
	public static Date formatStrToNormalDate(String dateStr) {
		return formatStrToDate(dateStr, NORMAL_DATETIME_FORMAT);
	}

	/**
	 * 获得按时间字符time(格式 "HH:mm:ss")转换的日期date
	 * @param date
	 * @param timeString 格式 "HH:mm:ss"
	 * @return 非法返回null
	 */
	public static Date getDateByTimeString(Date date, String timeString) {
		timeString = formatDateToString(date, String.format("yyyy-MM-dd %s", timeString));
		return formatStrToDate(timeString, NORMAL_DATETIME_FORMAT);
	}

	/**
	 * 功能描述：获取对应日期的开始时间
	 *
	 * @param date
	 * @return
	 */
	public static Date getDayStart(Date date) {
		String dateStartString = formatDateToString(date, "yyyy-MM-dd 00:00:00");
		return formatStrToDate(dateStartString, "yyyy-MM-dd HH:mm:ss");
	}

	/**
	 * 功能描述：获取对应日期的结束时间
	 *
	 * @param date
	 * @return
	 */
	public static Date getDayEnd(Date date) {
		String dateStartString = formatDateToString(date, "yyyy-MM-dd 23:59:59");
		return formatStrToDate(dateStartString, "yyyy-MM-dd HH:mm:ss");
	}

	public static String getDayEndString(Date date) {
		return formatDateToString(date, "yyyy-MM-dd 23:59:59");
	}

	public static Date getDay(Date date) {
		String dateStartString = formatDateToString(date, "yyyy-MM-dd 00:00:00");
		return formatStrToDate(dateStartString, "yyyy-MM-dd HH:mm:ss");
	}

	/**
	 * 获取date没有时分秒
	 * @param date
	 * @return
	 */
	public static Date getDayDate(Date date) {
		String dateStartString = formatDateToString(date, "yyyy-MM-dd");
		return formatStrToDate(dateStartString, "yyyy-MM-dd");
	}

	/**
	 * 功能描述：获取昨天的当前
	 *
	 * @return
	 * @version 1.0.0
	 * @since 1.0.0 create on: 2012-8-15
	 */
	public static Date getYesterday() {
		return getDayBefore(1);
	}

    /**
     * 功能描述：获取昨天的凌晨时间
     * @return
     */
	public static Date getYesterdayMidNight() {

        Calendar calendar = Calendar.getInstance();
        calendar.set(Calendar.DAY_OF_MONTH, calendar.get(Calendar.DAY_OF_MONTH) - 1);
        calendar.set(Calendar.HOUR_OF_DAY, 0);
        calendar.set(Calendar.MINUTE, 0);
        calendar.set(Calendar.SECOND, 0);
        calendar.set(Calendar.MILLISECOND, 0);
		return calendar.getTime();
	}

	/**
	 * 功能描述：获取前day天的日期
	 *
	 * @param day
	 * @return
	 * @version 1.0.0
	 * @since 1.0.0 create on: 2012-8-15
	 */
	public static Date getDayBefore(Integer day) {
		Calendar calendar = Calendar.getInstance();
		calendar.set(Calendar.DAY_OF_MONTH, calendar.get(Calendar.DAY_OF_MONTH) - day);
		return calendar.getTime();
	}

	public static Date getDayBefore(Date date, Integer day) {
		Calendar calendar = Calendar.getInstance();
		calendar.setTime(date);
		calendar.set(Calendar.DAY_OF_MONTH, calendar.get(Calendar.DAY_OF_MONTH) - day);
		return calendar.getTime();
	}

	public static Date getDayAfter(Date date, Integer day) {
		Calendar calendar = Calendar.getInstance();
		calendar.setTime(date);
		calendar.set(Calendar.DAY_OF_MONTH, calendar.get(Calendar.DAY_OF_MONTH) + day);
		return calendar.getTime();
	}

	public static Date getMonthBefore(Integer month) {
		Calendar calendar = Calendar.getInstance();
		calendar.set(Calendar.DAY_OF_MONTH, 1);
		//calendar.set(Calendar.MONTH, calendar.get(Calendar.MONTH) - month);
		calendar.add(Calendar.MONTH, -month);
		return calendar.getTime();
	}

	/**
	 * 获取当前日期的几个月前的信息。
	 * @param month
	 * @return
	 */
	public static Date getCurrentDateMonthBefore(Integer month) {
		Calendar calendar = Calendar.getInstance();
		//calendar.set(Calendar.MONTH, calendar.get(Calendar.MONTH) - month);
		calendar.add(Calendar.MONTH, -month);
		return calendar.getTime();
	}

	public static Date getDateMonthBefore(Date date, Integer month) {
		Calendar calendar = Calendar.getInstance();
		calendar.setTime(date);
		// 跨年有问题??
		//calendar.set(Calendar.MONTH, calendar.get(Calendar.MONTH) - month);
		calendar.add(Calendar.MONTH, -month);
		return calendar.getTime();
	}

	public static Date getMonthBefore(Date date, Integer month) {
		Calendar calendar = Calendar.getInstance();
		calendar.setTime(date);
		calendar.set(Calendar.DAY_OF_MONTH, 1);
		// 跨年有问题??
		//calendar.set(Calendar.MONTH, calendar.get(Calendar.MONTH) - month);
		calendar.add(Calendar.MONTH, -month);
		return calendar.getTime();
	}

	public static Date getMonthAfter(Date date, Integer month) {
		Calendar calendar = Calendar.getInstance();
		calendar.setTime(date);
		calendar.set(Calendar.DAY_OF_MONTH, 1);
		// 跨年有问题??
		//calendar.set(Calendar.MONTH, calendar.get(Calendar.MONTH) + month);
		calendar.add(Calendar.MONTH, month);
		return calendar.getTime();
	}

	/***
	 *
	 * 功能描述：获得当月，如2012-08
	 *
	 * @return
	 * @version 1.0.0
	 * @since 1.0.0 create on: 2012-8-17
	 */
	public static String getMonth() {
		String dateStartString = formatDateToString(new Date(), "yyyy-MM");
		return dateStartString;
	}

	public static Date getLastMonth() {
		return getMonthBefore(1);
	}

	public static boolean isMonthStart(Date date) {
		Calendar calendar = Calendar.getInstance();
		calendar.setTime(date);
		return calendar.get(Calendar.DAY_OF_MONTH) == 1;
	}

	public static boolean isMonthEnd(Date date) {
		Calendar calendar = Calendar.getInstance();
		calendar.setTime(date);
		calendar.add(Calendar.DAY_OF_MONTH, 1);
		return calendar.get(Calendar.DAY_OF_MONTH) == 1;
	}

	public static int getMonthDiff(Date bigDate, Date smallDate) {
		if (bigDate.compareTo(smallDate) <= 0) {
			return -1;
		}
		Calendar calInstance = Calendar.getInstance();
		calInstance.setTime(bigDate);
		int year1 = calInstance.get(Calendar.YEAR);
		int month1 = calInstance.get(Calendar.MONTH);
		calInstance.setTime(smallDate);
		int year2 = calInstance.get(Calendar.YEAR);
		int month2 = calInstance.get(Calendar.MONTH);
		return (year1 - year2) * 12 + month1 - month2;
	}

	public static int differentDays(Date date1,Date date2)
	{
		Calendar cal1 = Calendar.getInstance();
		cal1.setTime(date1);

		Calendar cal2 = Calendar.getInstance();
		cal2.setTime(date2);
		int day1= cal1.get(Calendar.DAY_OF_YEAR);
		int day2 = cal2.get(Calendar.DAY_OF_YEAR);

		int year1 = cal1.get(Calendar.YEAR);
		int year2 = cal2.get(Calendar.YEAR);
		if(year1 != year2)   //不同一年
		{
			int timeDistance = 0 ;
			for(int i = year1 ; i < year2 ; i ++)
			{
				if(i%4==0 && i%100!=0 || i%400==0)    //闰年
				{
					timeDistance += 366;
				}
				else    //不是闰年
				{
					timeDistance += 365;
				}
			}
			return timeDistance + (day2-day1) ;
		}
		else    //同年
		{
			return day2-day1;
		}
	}

	public static int getDayDiffByMillisecond(Date bigDate, Date smallDate) {
		if (bigDate.compareTo(smallDate) < 0) {
			return -1;
		}
		Long diff = (bigDate.getTime() - smallDate.getTime()) / 86400000;
		return diff.intValue();
	}

	/**
	 * 返回某个时间的"yyyy-MM-dd 00:00:00"字符串
	 * @param time
	 * @return
	 */
	public static String getTimeZeroString(Long time) {
		DateFormat simpleDateTimeZeroFormat = new SimpleDateFormat("yyyy-MM-dd 00:00:00");
		return simpleDateTimeZeroFormat.format(new Date(time));
	}

	public static int compareDate(Date date1, Date date2) {
		if (date1.getTime() > date2.getTime()) {
			return 1;
		} else if (date1.getTime() < date2.getTime()) {
			return -1;
		} else {
			return 0;
		}
	}

	/**
	 * 日期相减
	 *
	 * @param date
	 * 日期
	 * @param date1
	 * 日期
	 * @return 返回相减后的日期
	 */
	public static int diffDate(Date date, Date date1) {
		return (int) ((getMillis(date) - getMillis(date1)) / (24 * 3600 * 1000));
	}

	/**
	 * 年份相减
	 *
	 * @param date
	 * 日期
	 * @param date1
	 * 日期
	 * @return 返回相减后的年份
	 */
	public static int diffYear(Date date, Date date1) {
		return (int) (Math.abs((getMillis(date) - getMillis(date1))) / (24 * 3600 * 1000)) / 365;
	}
	/**
	 * 获取两个时间相差的毫秒数
	 *
	 * @param begin
	 * 开始时间
	 * @param end
	 * 结束时间
	 * @return end.getTime()-begin.getTime()
	 */
	public static Long diffMillis(Date begin, Date end) {
		return  end.getTime()-begin.getTime();
	}


	/**
	 * 返回毫秒
	 *
	 * @param date
	 * 日期
	 * @return 返回毫秒
	 */
	public static long getMillis(Date date) {
		Calendar c = Calendar.getInstance();
		c.setTime(date);
		return c.getTimeInMillis();
	}
	/***
     * checkDate是否在当前时间之前
     * @param checkDate
     * @return
     */
    public static boolean isNowBefore(Date checkDate) {

        Calendar checkCal = Calendar.getInstance(Locale.CHINA);
        Calendar nowCal = Calendar.getInstance(Locale.CHINA);

        checkCal.setTime(checkDate);
        nowCal.setTime(new Date());

        return checkCal.before(nowCal);
    }


    /***
     * checkDate是否在当前时间之后
     * @param checkDate
     * @return
     */
    public static boolean isNowAfter(Date checkDate) {
		Calendar checkCal = Calendar.getInstance(Locale.CHINA);
        Calendar nowCal = Calendar.getInstance(Locale.CHINA);

        checkCal.setTime(checkDate);
		nowCal.setTime(new Date());

        return checkCal.after(nowCal);
    }



	/**
	 * 判断checkDate时间是否在当前时间之后
	 * @param beginDate 开始时间
	 * @param endDate 结束时间
	 * @return boolean
	 */
	public static boolean isNowBetween(Date beginDate,Date endDate) {

        Calendar beginCal = Calendar.getInstance(Locale.CHINA);
        Calendar nowCal = Calendar.getInstance(Locale.CHINA);
        Calendar endCal = Calendar.getInstance(Locale.CHINA);

        beginCal.setTime(beginDate);
        endCal.setTime(endDate);
        nowCal.setTime(new Date());

        return nowCal.after(beginCal)&&nowCal.before(endCal);
    }
    /**
     * 将字符串转换为日期（包括时间）
     * @param dateTimeString "yyyy-MM-dd HH:mm:ss"格式的日期字符串
     * @return 日期时间
     */
    public static Date convertToDateTime(String dateTimeString) {
        try {
            return DATE_TIME_FORMAT.parse(dateTimeString);
        } catch (ParseException e) {
            return null;
        }
    }

	/**
	 * 获取当前时间距离今日凌晨：00：00：00之间的秒数
	 * 〈功能详细描述〉
	 *
	 * @return int 剩余秒数
	 */
	public static int getTodayLeftSecounds() {
		Date date = new Date();
		int i = (int) ((getMillis(getDayEnd(date)) - getMillis(date)) / (1000));
		if(i < 1)
			i = 10;
		return i;
	}

	public static Date getDateFromTimestamp(String longMillis) {
		if (StringUtils.isBlank(longMillis)) {
			return  null;
		}
		if (longMillis.length() < 12) {
			longMillis = longMillis + "000";
			return new Date(Long.parseLong(longMillis));
		}
		return new Date(Long.parseLong(longMillis));
	}

	public static int getTodayLeftMiao(){
		Calendar curDate = Calendar.getInstance();
		Calendar tommorowDate = new GregorianCalendar(curDate
				.get(Calendar.YEAR), curDate.get(Calendar.MONTH), curDate
				.get(Calendar.DATE) + 1, 0, 0, 0);
		return (int)(tommorowDate.getTimeInMillis() - curDate .getTimeInMillis()) / 1000;
	}

	/**
	 * 现在到下周一的时间差（秒）
	 * @param todayDate
	 * @return
	 */
	public static int getNextMonday(Date todayDate) {
		int mondayPlus = 0;
		Calendar todayCalendar = Calendar.getInstance();
	    todayCalendar.setTime(todayDate);
	    // 获得今天是一周的第几天，星期日是第一天，星期二是第二天......
	    int dayOfWeek = todayCalendar.get(Calendar.DAY_OF_WEEK) - 1; // 因为按中国礼拜一作为第一天所以这里减1
	    if (dayOfWeek == 1) {
	    	mondayPlus = 0;
	    } else {
	    	mondayPlus = 1 - dayOfWeek;
	    }

	    GregorianCalendar currentDate = new GregorianCalendar();
	    currentDate.add(GregorianCalendar.DATE, mondayPlus + 7);
	    Date monday = currentDate.getTime();

	    Calendar calendar = Calendar.getInstance();
	    calendar.setTime(monday);
	    Calendar mondaycCalendar = new GregorianCalendar(calendar.get(Calendar.YEAR),
	    		calendar.get(Calendar.MONTH),
	    		calendar.get(Calendar.DATE), 0, 0, 0);

	    return (int)(mondaycCalendar.getTimeInMillis() - todayCalendar.getTimeInMillis()) / 1000;
	}
	/**
	 *
	 * 获取信息流中的每条信息的发布时间.
	 * 	1、发布时间距离当前时间≤1小时，则显示X分钟前；
	 *	2、1小时＜发布时间距离当前时间≤24小时，则显示X小时前；
	 *	3、24小时＜发布时间距离当前时间，则按天：
	 *	1）当前日期-发布日期=1时，则显示昨天；显示1小时前；
	 *	2）当前-发布日期≥X（X≥2）天时，则显示X天前。
	 * @return
	 */
	public static String formatTimeStrForFeed(Date date) {
		long curTime = System.currentTimeMillis();
		long dateTime = date.getTime();
		long interval = curTime - dateTime;
		if (interval < 0) {
			return "刚刚";
		} else if (interval <= 3600000) {
			long minutes = interval / 60000;
			return minutes == 0 ? "刚刚" : minutes + "分钟前";
		} else if (interval <= 3600000 * 24) {
			long hours = interval / 3600000;
			return hours + "小时前";
		} else {
			int diffDate = diffDate(new Date(), date);
//			int diffDate = (int) (interval / (3600000 * 24));
			if (diffDate == 1) {
				return "昨天";
			} else {
				return diffDate + "天前";
			}
		}
	}


	/**
	 * 进行中：0<=T<2小时，即话题已经在开播，但是开播不到2个小时，且未结束；
	 * XX分钟后：-1(小时)<T<0，即话题未开播，距离开播时间不到1小时，且未结束；
	 * XX小时后：-24(小时)<T=<-1，即话题未开播，距离开播时间超过1小时，不到24小时，且未结束;
	 * XX天后：T<=-24(小时)，即话题未开播，距离开播时间超过24小时，且未结束；
	 * */
	public static String formatTimeStrForFeedV2 (Date date) {
		long curTime = System.currentTimeMillis();
		long dateTime = date.getTime();
		long interval = curTime - dateTime; //秒
		long beforeBeginTime = dateTime - curTime;
		if (interval >= 0 || beforeBeginTime < 60000) {
			return "进行中";
		} else if (beforeBeginTime < 3600000) {
			long minutes = beforeBeginTime / 60000;
			return minutes + "分钟后";
		} else if (beforeBeginTime < 3600000 * 24) {
			long hours = beforeBeginTime / 3600000;
			return hours + "小时后";
		} else {
			int diffDate = (int) (beforeBeginTime / (3600000 * 24));
			return diffDate + "天后";
		}
	}

    /**
     * 今天 20:00
     * 昨天 20:00
     * 大于等于前天的：2017-01-01 00:00:00
     * @param date
     * @return
     */
    public static String formatTimeStrForFeedV3(Date date) {
        Date today = new Date();
        String time;
        if(isSameDate(date, today)) {
            time = DateUtil.dateToString(date, TIME_FORMAT);
            return "今天 " + time;
        } else {
            int differenceDays = differentDays(date, today);
            if(differenceDays == 1) {
                time = DateUtil.dateToString(date, TIME_FORMAT);
                return "昨天 " + time;
            } else {
                time = DateUtil.dateToString(date, NORMAL_DATETIME_FORMAT_NO_SECOND);
                return time;
            }
        }
    }

    public static String formatTimeStrForFeed (Long time) {
	    Date date = formatTimeLongToDate(time);
	    return formatTimeStrForFeed(date);
    }

	//根据日期取得星期几
    public static String getChineseWeek(Date date){
        String[] weeks = {"周日","周一","周二","周三","周四","周五","周六"};
        Calendar cal = Calendar.getInstance();
        cal.setTime(date);
        int week_index = cal.get(Calendar.DAY_OF_WEEK) - 1;
        if(week_index<0){
            week_index = 0;
        }
        return weeks[week_index];
    }

	//根据日期取得星期几  ，返回数字
    public static String getNumberWeek(Date date){
        String[] weeks = {"0","1","2","3","4","5","6"};
        Calendar cal = Calendar.getInstance();
        cal.setTime(date);
        int week_index = cal.get(Calendar.DAY_OF_WEEK) - 1;
        if(week_index<0){
            week_index = 0;
        }
        return weeks[week_index];
    }

	/**
	 * 获取时间戳
	 */
	public static String getTimeString() {
		SimpleDateFormat df = new SimpleDateFormat(FORMAT_FULL);
		Calendar calendar = Calendar.getInstance();
		return df.format(calendar.getTime());
	}


	/**
	 * 功能描述：返回分
	 *
	 * @param date
	 *            日期
	 * @return 返回分钟
	 */
	public static int getMinute(Date date) {
		Calendar calendar = Calendar.getInstance();
		calendar.setTime(date);
		return calendar.get(Calendar.MINUTE);
	}
	/**
	 * 比较两个时间的天数
	 * @author HuangLinWei
	 * @since 2018/7/20
	 * @param date1
	 * @param date2
	 * @return boolean
	 */
	public static int daysOfTwo(Date date1, Date date2) {
		Calendar aCalendar = Calendar.getInstance();
		aCalendar.setTime(date1);
		int day1 = aCalendar.get(Calendar.DAY_OF_YEAR);
		aCalendar.setTime(date2);
		int day2 = aCalendar.get(Calendar.DAY_OF_YEAR);
		return day2 - day1;
	}
	/**
	 * 判断是否同一天
	 *
	 * @param date1
	 * @param date2
	 * @return isSameYear && isSameMonth && isSameDate
	 */
	public static boolean isSameDate(Date date1, Date date2) {
		if (date1 == null || date2 == null) {
			return false;
		}
		Calendar cal1 = Calendar.getInstance();
		cal1.setTime(date1);

		Calendar cal2 = Calendar.getInstance();
		cal2.setTime(date2);

		boolean isSameYear = cal1.get(Calendar.YEAR) == cal2.get(Calendar.YEAR);
		boolean isSameMonth = isSameYear && cal1.get(Calendar.MONTH) == cal2.get(Calendar.MONTH);
		boolean isSameDate = isSameMonth && cal1.get(Calendar.DAY_OF_MONTH) == cal2.get(Calendar.DAY_OF_MONTH);

		return isSameDate;
	}
	/**
	 * 判断是否同一天
	 *
	 * @param date1
	 * @param date2
	 * @return isSameYear && isSameMonth && isSameDate && isSameHour && isSameMinute
	 * @since kuai 1.0
	 */
	public static boolean isSameDateTime(Date date1, Date date2) {
		if (date1 == null || date2 == null) {
			return false;
		}
		Calendar cal1 = Calendar.getInstance();
		cal1.setTime(date1);

		Calendar cal2 = Calendar.getInstance();
		cal2.setTime(date2);

		boolean isSameYear = cal1.get(Calendar.YEAR) == cal2.get(Calendar.YEAR);
		boolean isSameMonth = isSameYear && cal1.get(Calendar.MONTH) == cal2.get(Calendar.MONTH);
		boolean isSameDate = isSameMonth && cal1.get(Calendar.DAY_OF_MONTH) == cal2.get(Calendar.DAY_OF_MONTH);
		boolean isSameHour = isSameDate && cal1.get(Calendar.HOUR_OF_DAY) == cal2.get(Calendar.HOUR_OF_DAY);
		boolean isSameMinute = isSameHour && cal1.get(Calendar.MINUTE) == cal2.get(Calendar.MINUTE);

		return isSameMinute;
	}

	public static Integer getDay() {
		Calendar cal = Calendar.getInstance();
		return cal.get(Calendar.DATE);
	}

	public static Integer getDayByDate(Date date) {
		Calendar cal = Calendar.getInstance();
		cal.setTime(date);
		return cal.get(Calendar.DATE);
	}

	/**
	 * 小时差
	 * @param date
	 * @param date2
	 * @return
	 */
	public static int diffHour(Date date, Date date2) {
		return (int) ((getMillis(date) - getMillis(date2)) / (60 * 60 * 1000));
	}
	/**
	 * 分钟差
	 * @param date
	 * @param date2
	 * @return
	 */
	public static int diffMin(Date date, Date date2) {
		return (int) ((getMillis(date) - getMillis(date2)) / (60 * 1000));
	}

	/**
	 * 时间差：
	 * 大于24小时：天数
	 * 小于24小时大于一小时：小时数
	 * 小于一小时大于一分钟：分钟数
	 * 小于一分钟：1分钟
	 * @param date
	 * @param date2
	 * @return
	 */
	@SuppressWarnings("deprecation")
	public static String diffDateAfter(Date date, Date date2) {
		String dateAfter = null;
		Date currentDate = new Date();
		int day = DateUtil.diffDate(date, currentDate);
		if(day > 0) { // n天后

			//小于24小时的也需要+1
			if((date.getHours() - currentDate.getHours()) <= 0) {
				day++;
			}

			dateAfter = day + "天";
		} else if (day == 0) {
			day = DateUtil.diffHour(date, currentDate);
			if(day > 0) { //n小时后
				dateAfter = day + "小时";
			} else {
				day = DateUtil.diffMin(date, currentDate);
				if(day > 0) {
					dateAfter = day + "分钟";
				} else if (day == 0) {
					dateAfter = "1分钟";
				}
			}
		}
		return dateAfter;
	}

	/**
	 * 通过活动开启天数，活动总天数，计算出进度,取整
	 */
	public static int getProcess(int liveDay, int totalDay) {
		if(liveDay == 0)
			return 0;
		if(liveDay == totalDay)
			return 100;
		BigDecimal yy = new BigDecimal(liveDay);
		BigDecimal xx = new BigDecimal(totalDay);
		int result = (int)Math.ceil(yy.divide(xx, 4, BigDecimal.ROUND_FLOOR).multiply(new BigDecimal(100)).doubleValue());
		return result;
	}

	/**
	 * 通过开始时间，结束时间，当前时间，计算出进度,取整
	 */
	public static int getProcess(Date startTime, Date endTime) {
		Date currentTime = new Date();
		if(currentTime.before(startTime)) { //未开始：0
			return 0;
		}
		if(isSameDate(currentTime, endTime) || currentTime.after(endTime)) { //结束当天之后：100
			return 100;
		}
		//结束时间-开始时间间距
		int x = diffDate(endTime, startTime) + 1;
		if(x == 0) {
			return 0;
		}
		//当前时间-开始时间间距
		int y = diffDate(currentTime, startTime) + 1;
		BigDecimal yy = new BigDecimal(y);
		BigDecimal xx = new BigDecimal(x);

		int result = (int)Math.ceil(yy.divide(xx, 4, BigDecimal.ROUND_FLOOR).multiply(new BigDecimal(100)).doubleValue());
		return result;
	}

    /**
     * long转date
     * @param time
     * @return
     */
	public static Date formatTimeLongToDate(Long time) {
        Date date = new Date(time);
        return date;
    }

    /**
     * 判断是否在活动时间内
     * @param nowDate
     * @return
     */
    public static boolean isActivityTime(Date nowDate, Date startDate, Date endDate) {
        if(!DateUtil.isSameDate(startDate, nowDate) && !DateUtil.isSameDate(endDate, nowDate)) {
            long today = nowDate.getTime();
            long startTime = startDate.getTime();
            long endTime = endDate.getTime();
            if(today < startTime  //活动开始之前
                    || today > endTime) //活动已经结束
                return false;
        }
        //在活动开始当天、结束当天
        return true;
    }

	/**
	 * 是否结束
	 * @param endTime
	 * @return true: 已经结束
	 */
	public static boolean isDateEnded(Date endTime) {
		long now = System.currentTimeMillis();
    	if(now > endTime.getTime()) {
			return true;
		}
		return false;
	}

	/**
	 * 活动是否开始
	 * @param startTime
	 * @return
	 */
	public static boolean isDateStart(Date startTime) {
		long now = System.currentTimeMillis();
		if(now >= startTime.getTime()) {
			return true;
		}
		return false;
	}

	/**
	 * 获取当天零点时间戳
	 * @return
	 */
	public static Long getDayZeroTime() {
		return DateUtil.getToday().getTime();
	}

	/**
	 * 获取一段时间内时间戳
	 * @param hours 小时
	 * @return
	 */
	public static Long getTimeStampByHour(Integer hours) {
		return hours.longValue() * 3600 * 1000;
	}



	public static String getWeekDayEn(Date date) {
		String dayEn = null;
		switch (date.getDay()) {
			case 1:
				dayEn = "Monday";
				break;
			case 2:
				dayEn = "Tuesday";
				break;
			case 3:
				dayEn = "Wednesday";
				break;
			case 4:
				dayEn = "Thursday";
				break;
			case 5:
				dayEn = "Friday";
				break;
			case 6:
				dayEn = "Saturday";
				break;
			case 0:
				dayEn = "Sunday";
				break;
		}
		return dayEn;
	}

	/**
	 * 计算总天数
	 * 按照周第一天是星期天
	 * @param startTime
	 * @param endTime
	 * @param weekDayOff
	 * @return
	 */
	public static int getTotalDay(Date startTime, Date endTime, List<Integer> weekDayOff) {
		int num1 = 0, num2 = 0, num3 = 0, totalDay = 0, tempTotalDay = 0, weekNum = 0;
		int day1 = startTime.getDay();
		int day3 = endTime.getDay();
		Date tempStartTime, tempEndTime;

		if(isSameDate(startTime, endTime)) {
			return 1;
		}

		if(day1 == 0 && day3 == 6) { //0:星期天
			totalDay = differentDays(startTime, endTime) + 1;
			weekNum = totalDay / 7; //理论上是整除
			totalDay = totalDay - (weekNum * weekDayOff.size());
		} else {
			if (day1 > 0) { //计算第一段
				num1 = 6 - day1 + 1;
				tempStartTime = addDateDay(startTime, num1);

				//减去不需要打卡的天数
				for (int i = day1; i < 7; i++) {
					if(weekDayOff.contains(i)) {
						num1--;
					}
				}
			} else {
				tempStartTime = startTime;
			}
			if (day3 < 6) { //计算第三段
				num3 = day3 + 1;
				tempEndTime = addDateDay(endTime, -num3);

				//减去不需要打卡的天数
				for (int i = 0; i < day3 + 1; i++) {
					if(weekDayOff.contains(i)) {
						num3--;
					}
				}
			} else {
				tempEndTime = endTime;
			}
			//计算第二段
			tempTotalDay = differentDays(tempStartTime, tempEndTime) + 1;
			weekNum = tempTotalDay / 7; //理论上是整除
			num2 = tempTotalDay - (weekNum * weekDayOff.size());
			totalDay = num1 + num2 + num3;
//			logger.error("num1:{}, num2:{}, num3:{}, ", num1, num2, num3);
//			logger.error("tempTotalDay:{}, tempStartTime:{}, tempEndTime:{}, ", tempTotalDay, tempStartTime, tempEndTime);
		}
		return totalDay;
	}

    /**
     * 获取当前时间前刚好半小时的时间点，30分，00分
     *
     * @return java.lang.String
     * @author weiys
     * @since 2018/10/12 17:16
     */
    public static String getHalfHourBefore() {
        Calendar calendar = Calendar.getInstance();
        int minute = calendar.get(Calendar.MINUTE);
        String format;
        if (minute < 30) {
            format = format(new Date(), NORMAL_DATETIME_FORMAT_HOUR) + ":00";
        } else {
            format = format(new Date(), NORMAL_DATETIME_FORMAT_HOUR) + ":30";
        }
        return format;
    }

    /**
     * 获取当前时间后刚好半小时的时间点，30分，00分
     *
     * @return java.lang.String
     * @author weiys
     * @since 2018/10/12 17:16
     */
    public static String getHalfHourAfter() {
        Calendar calendar = Calendar.getInstance();
        int minute = calendar.get(Calendar.MINUTE);
        String format;
        if (minute < 30) {
            format = format(new Date(), NORMAL_DATETIME_FORMAT_HOUR) + ":30";
        } else {
            int hour = calendar.get(Calendar.HOUR_OF_DAY) + 1;
            format = format(new Date(), NORMAL_DATE_FORMAT) + " " + hour + ":00";
        }
        return format;

    }

	/**
	 * 获取上周的周一 'yyyy-MM-dd'（中国式周）
	 *
	 * @param strDate 指定日期字符串
	 * @param format  日期格式
	 * @author zhouc
	 */
	public static String getMondayOfLastweekChina(String strDate, String format) {
		Calendar cal = Calendar.getInstance();
		try {
			cal.setTime(parse(strDate, format));
		} catch (ParseException e) {
			e.printStackTrace();
			return null;
		}
		// 若当天是周日
		if (cal.get(Calendar.DAY_OF_WEEK) == 1) {
			cal.add(Calendar.DATE, -6 -7);
		} else {
			cal.add(Calendar.DATE, (-cal.get(Calendar.DAY_OF_WEEK) + 2)-7);
		}
		return format(cal.getTime());
	}

	/**
	 * 获取指定日期那周的周一 'yyyy-MM-dd'（中国式周）
	 *
	 * @param strDate 指定日期字符串
	 * @param format  日期格式
	 * @author weiys
	 * @date 2018/6/21 22:56
	 */
	public static String getMondayOfWeekChina(String strDate, String format) {
		Calendar cal = Calendar.getInstance();
		try {
			cal.setTime(parse(strDate, format));
		} catch (ParseException e) {
			e.printStackTrace();
			return null;
		}
		// 若当天是周日
		if (cal.get(Calendar.DAY_OF_WEEK) == 1) {
			cal.add(Calendar.DATE, -6);
		} else {
			cal.add(Calendar.DATE, -cal.get(Calendar.DAY_OF_WEEK) + 2);
		}
		return format(cal.getTime());
	}

	/**
	 * 获取指定日期那周的周一
	 * @param date
	 * @return
	 */
	public static String getMondayOfWeekChina(Date date) {
		Calendar cal = Calendar.getInstance();
		cal.setTime(date);
		// 若当天是周日
		if (cal.get(Calendar.DAY_OF_WEEK) == 1) {
			cal.add(Calendar.DATE, -6);
		} else {
			cal.add(Calendar.DATE, -cal.get(Calendar.DAY_OF_WEEK) + 2);
		}
		return format(cal.getTime());
	}


	/**
	 * 获取指定日期那周的周天 'yyyy-MM-dd'（中国式周）
	 *
	 * @param strDate 指定日期字符串
	 * @param format  日期格式
	 * @author weiys
	 * @date 2018/6/21 22:56
	 */
	public static String getSundayOfWeekChina(String strDate, String format) {
		Calendar cal = Calendar.getInstance();
		try {
			cal.setTime(parse(strDate, format));
		} catch (ParseException e) {
			e.printStackTrace();
			return null;
		}
		// 若当天不是是周日
		if (cal.get(Calendar.DAY_OF_WEEK) != 1) {
			cal.add(Calendar.DATE, -cal.get(Calendar.DAY_OF_WEEK) + 8);
		}
		return format(cal.getTime());

	}

	/**
	 * 将日期字符串转换为绝对毫秒值
	 *
	 * @param dateStr 日期字符串
	 * @param pattern 要转换的日期格式
	 * @author: weiys
	 * @date: 2018/6/7 16:46
	 */
	public static long converDateStr2TimeStamp(String dateStr, String pattern) {
		try {
			return DateUtil.parse(dateStr, pattern).getTime();
		} catch (ParseException e) {
			e.printStackTrace();
			return 0;
		}
	}

	/**
	 * 获取当天开始时间、结束时间
	 *
	 * @param date
	 * @return
	 */
	public static Map<String, Long> getTodayStartTimeAndEndTime(String date) {
		Date startTime = DateUtil.parseSimple(date + " 00:00:00");
		Date endTime = DateUtil.addDateDay(startTime, 1);
		long endTimeStamp = endTime.getTime() - 1;

		Map<String, Long> map = new HashMap<>();
		map.put("startTime", startTime.getTime());
		map.put("endTime", endTimeStamp);
		return map;
	}

	/**
	 * 获取两个时间段的开始时间、结束时间，时间戳
	 * @return
	 */
	public static Map<String, Long> getStartTimeAndEndTime(String startDate, String endDate) {
		Date startTime = DateUtil.parseSimple(startDate + " 00:00:00");
		Date endTime = DateUtil.parseSimple(endDate + " 00:00:00");
		Date endTime2 = DateUtil.addDateDay(endTime, 1);
		long endTimeStamp = endTime2.getTime() - 1;

		Map<String, Long> map = new HashMap<>();
		map.put("startTime", startTime.getTime());
		map.put("endTime", endTimeStamp);
		return map;
	}

	/**
	 * 闯关模式：获取第二天中午14点的时间戳
	 */
	public static long getDay14Hour(Long createTime, int offset) {
		Calendar cal = Calendar.getInstance();
		cal.setTime(new Date(createTime));
		cal.set(Calendar.HOUR_OF_DAY, 14);
		cal.set(Calendar.MINUTE, 0);
		cal.set(Calendar.SECOND, 0);
		cal.set(Calendar.MILLISECOND, 0);
		cal.add(Calendar.DAY_OF_YEAR, offset);
		return cal.getTime().getTime();
	}

	/**
	 * 获取两个日期之间的所有日期
	 */
	public static List<Date> getBetweenDates(Date start, Date end) {
		List<Date> result = new ArrayList<Date>();

		Calendar tempStart = Calendar.getInstance();
		tempStart.setTime(start);

		while (start.getTime() <= end.getTime()) {
			result.add(tempStart.getTime());
			tempStart.add(Calendar.DAY_OF_YEAR, 1);
			start = tempStart.getTime();
		}
		return result;
	}

	/**
	 * 当前时间距离0点的秒数
	 */
	public static Long getDistanceZeroSecond() {
		Long toDaySecond = getTodayLast().getTime();
		Long currentSecond = System.currentTimeMillis();
		return (toDaySecond - currentSecond) / 1000;
	}

	/**
	 * 当前时间距离0点的秒数
	 */
	public static Long getDistanceZeroSecond(Date date) {
		Long toDaySecond = DateUtil.getDayEnd(date).getTime();
		Long currentSecond = date.getTime();
		return (toDaySecond - currentSecond) / 1000;
	}

	/**
	 * 根据日期返回中文字
	 * 今日 昨天
	 * @param date
	 * @return
	 */
	public static String getDateCn(String date) {
		if (StringUtils.isBlank(date)) {
			return date;
		}

		String today = formatCurrentDate();
		if (today.equals(date)) {
			return "今日";
		}

		String yesterday = addDateStr(new Date(), -1, DATE);
		if (yesterday.equals(date)) {
			return "昨天";
		}

		return date;
	}


	/**
	 * 将秒转成时分秒
	 * @param date
	 * @return
	 */
	public static String msecToTime(long time) {
	    String timeStr = null;
	    long hour = 0;
	    long minute = 0;
	    long second = 0;
	 //   int millisecond = 0;
	    if (time <= 0)
	        return "00:00:00";
	    else {
	        second = time / 1000;
	        minute = second / 60;
	     //   millisecond = time % 1000;
	        if (second < 60) {
	            timeStr = "00:00:" + unitFormat(second) ;
	        } else if (minute < 60) {
	            second = second % 60;
	            timeStr = "00:" + unitFormat(minute) + ":" + unitFormat(second) ;
	        } else {// 数字>=3600 000的时候
	            hour = minute / 60;
	            minute = minute % 60;
	            second = second - hour * 3600 - minute * 60;
	            timeStr = unitFormat(hour) + ":" + unitFormat(minute) + ":" + unitFormat(second) ;

	        }
	    }
	    return timeStr;
	}

	public static String unitFormat(long i) {// 时分秒的格式转换
		String retStr = null;
		if (i >= 0 && i < 10)
			retStr = "0" + Long.toString(i);
		else
			retStr = "" + i;
		return retStr;
	}

	/**
	 * 获取当前时间至前30天
	 * @return
	 */
	public static String[] dateStr(){
		String [] dateTime = new String [2];
		SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd ");
		Calendar calendar = Calendar.getInstance();
		Date now = calendar.getTime();
		String endTime = simpleDateFormat.format(now);
		calendar.set(Calendar.MONTH, calendar.get(Calendar.MONTH));
		//calendar.getMaximum(Calendar.DATE)-1
		calendar.set(Calendar.DATE, -29);
		calendar.set(Calendar.HOUR, -12);
		calendar.set(Calendar.MINUTE, 0);
		calendar.set(Calendar.SECOND, 0);
		Date date = calendar.getTime();
		String startTime = simpleDateFormat.format(date);
		dateTime[0]=startTime;
		dateTime[1]=endTime;
		return dateTime;
	}

	/**
	 * 几天后日期
	 * @param m 天数
	 * @return 格式：yyyy-MM-dd
	 */
	public static String addDays(int m) {
		Calendar c = Calendar.getInstance();
        c.setTime(new Date());
        c.add(Calendar.DATE, m);
        return new SimpleDateFormat("yyyy-MM-dd").format(c.getTime());
	}


	 /**
     * 获得年龄
     *
     * @param dateString yyyy-MM-dd
     * @return 岁/月/周/天 如2岁3月
     * @author 章伏清
     */
    public static String getAge(String dateString){
        if (StringUtils.isBlank(dateString)) {
            return "";
        }

        Calendar c = Calendar.getInstance();
        Calendar b = Calendar.getInstance();
        Date date = null;
        try {
            date = new SimpleDateFormat("yy-MM-dd").parse(dateString);
        } catch (ParseException e) {
            e.printStackTrace();
        }
        b.setTime(date);
        int y = c.get(Calendar.YEAR);
        int m = c.get(Calendar.MONTH);//注意此处，如果不加1的话计算结果是错误的
        int d = c.get(Calendar.DAY_OF_MONTH);

        int by = b.get(Calendar.YEAR);
        int bm = b.get(Calendar.MONTH);
        int bd = b.get(Calendar.DAY_OF_MONTH);

        int age = y - by;
        int month = m - bm;
        int day = d - bd;
        if (day < 0) {
            month--;
            day += 30;
        }

        if (month < 0) {
            age--;
            month += 12;
        }

        if (age == 0 && month == 0) {
            day = getBirthDays(dateString);
        }

        int week = day / 7;
        day = day % 7;

        String s = "";
        if (age > 0) {
            s = age + "岁";
        }
        if (month > 0 && age < 6) {
            s += month + "月";
        }
        if (week > 0 && age == 0) {
            s += week + "周";
        }
        if (day > 0 && age == 0) {
            s += day + "天";
        }
        return s;
    }

    /**
     * 获得出生天数
     * @param dateString
     * @return
     * @author 章伏清
     */
    public static int getBirthDays(String dateString){
        Calendar now = Calendar.getInstance();

        Calendar post = Calendar.getInstance();
        Date date = null;
        try {
            date = new SimpleDateFormat("yy-MM-dd").parse(dateString);
        } catch (ParseException e) {
            e.printStackTrace();
        }
        post.setTime(date);
        return (int)((now.getTimeInMillis()- post.getTimeInMillis())/86400000);
    }

    /**
     * 提前或延后几分钟
     * @param date 格式：yyyy-MM-dd HH:mm
     * @param m 分钟数（正数往后延，负数往前推）
     * @return 格式：yyyy-MM-dd HH:mm
     */
    public static String addMinutes1(String date, int m){
        Date d = null;
        Calendar c = Calendar.getInstance();
        try {
            d = new SimpleDateFormat("yy-MM-dd HH:mm").parse(date);
        } catch (ParseException e) {
            e.printStackTrace();
        }
        c.setTime(d);
        c.add(Calendar.MINUTE, m);
        return new SimpleDateFormat("yyyy-MM-dd HH:mm").format(c.getTime());
    }

    /**
     * 时间前推或时间后延几分钟HH:mm
     * @param date 格式：HH:mm
     * @param m 分钟（正数往后延，负数往前推）
     * @return HH:mm
     */
    public static String addMinutes2(String date, int m) {
        try {
            Calendar c = Calendar.getInstance();
            c.setTime(new SimpleDateFormat("HH:mm").parse(date));
            c.add(Calendar.MINUTE, m);
            return new SimpleDateFormat("HH:mm").format(c.getTime());
        } catch (ParseException e) {
            e.printStackTrace();
        }
        return "";
    }

    /**
     * 提前或延后几分钟
     * @param date 格式：yyyy-MM-dd HH:mm:ss
     * @param m 分钟数（正数往后延，负数往前推）
     * @return 格式：yyyy-MM-dd HH:mm:ss
     */
    public static String addMinutes(String date, int m){
        Date d = null;
        Calendar c = Calendar.getInstance();
        try {
            d = new SimpleDateFormat("yy-MM-dd HH:mm:ss").parse(date);
        } catch (ParseException e) {
            e.printStackTrace();
        }
        c.setTime(d);
        c.add(Calendar.MINUTE, m);
        return new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(c.getTime());
    }

    /**
     * 几天后日期
     * @param date 格式：  yyyy-MM-dd
     * @param m 天数
     * @return  格式： yyyy-MM-dd
     */
    public static String addDays2(String date, int m){
        Date d = null;
        Calendar c = Calendar.getInstance();
        try {
            d = new SimpleDateFormat("yy-MM-dd").parse(date);
        } catch (ParseException e) {
            e.printStackTrace();
        }
        c.setTime(d);
        c.add(Calendar.DATE, m);
        return new SimpleDateFormat("yyyy-MM-dd").format(c.getTime());
    }

    /**
     * 计算两日期间的分钟差
     *
     * @Description: 简单描述该方法的实现功能
     * @param start yyyy-MM-dd HH:mm
     * @param end   yyyy-MM-dd HH:mm
     * @return
     * @author fan
     * @date 2018年6月13日 下午3:09:50
     */
    public static int getIntervalMinus(String start, String end) {
        Calendar sc = Calendar.getInstance();

        Calendar ec = Calendar.getInstance();
        Date sdate = null;
        Date edate = null;
        try {
            sdate = new SimpleDateFormat("yy-MM-dd HH:mm").parse(start);
            edate = new SimpleDateFormat("yy-MM-dd HH:mm").parse(end);
        } catch (ParseException e) {
            e.printStackTrace();
        }
        sc.setTime(sdate);
        ec.setTime(edate);
        return Math.abs((int)((ec.getTimeInMillis() - sc.getTimeInMillis())/60000));
    }

    /**
     * 判断日期是否过期
     *
     * @param dateString 格式：yyyy-MM-dd
     * @return true:过期，false:没过期
     * @author 章伏清
     */
    public static boolean isOverdue(String dateString){
        String today = new SimpleDateFormat("yyyy-MM-dd").format(new Date());
        return today.compareTo(dateString)>0?true:false;
    }

	/**
	 * 获得日期间隔天数
	 * @param start yyyy-MM-dd
	 * @param end 	yyyy-MM-dd
	 * @return
	 * @author
	 */
	public static int getIntervalDays(String start, String end){
		Calendar sc = Calendar.getInstance();

		Calendar ec = Calendar.getInstance();
		Date sdate = null;
		Date edate = null;
		try {
			sdate = new SimpleDateFormat("yy-MM-dd").parse(start);
			edate = new SimpleDateFormat("yy-MM-dd").parse(end);
		} catch (ParseException e) {
			e.printStackTrace();
		}
		sc.setTime(sdate);
		ec.setTime(edate);
		return Math.abs((int)((ec.getTimeInMillis()- sc.getTimeInMillis())/86400000));
	}

	/**
	 * 获得指定日期所在星期几
	 *
	 * @param dateString
	 * @return
	 * @author
	 */
	public static String getWeek(String dateString){
		Calendar c = Calendar.getInstance();
		Date date = null;
		try {
			date = new SimpleDateFormat("yy-MM-dd").parse(dateString);
		} catch (ParseException e) {
			e.printStackTrace();
		}
		c.setTime(date);

		return String.valueOf(c.get(Calendar.DAY_OF_WEEK)-1<0?0:c.get(Calendar.DAY_OF_WEEK)-1);
	}

	/**
	 * 获取当前日期
	 * @return 格式：yyyy-MM-dd
	 * @author
	 */
	public static String getCurrDate() {
		Date date = new Date();
		if (date != null && !date.equals("")) {
			SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
			String result = null;
			result = format.format(date);
			return result;
		} else {
			return null;
		}
	}

	/**
	 * 获取当前时间
	 * @return 格式：HH:mm:ss
	 * @author
	 */
	public static String getCurrentTime(){
		return new SimpleDateFormat("HH:mm:ss").format(new Date());
	}

	/**
	 * 功能描述:    天数转换为年龄
	 *
	 * @MethodName:
	 * @Description:    天数 ===> yyyy-MM-dd ===> 年龄
	 * @param day
	 * @return
	 * @author ouzhenye
	 * @Date 2019/8/6 16:02
	 **/
	public static String day2Age(int day) {
		String dateStr = DateUtil.addDays(-day);
		return DateUtil.getAge(dateStr);
	}

	/**
	 * 功能描述:   年龄 转换为 天数
	 *
	 * @MethodName:
	 * @Description: 岁月周天(换算)==》yyyy-MM-dd ==》天数
	 * @param age 例如：1岁1月1周100天
	 * @return
	 * @author ouzhenye
	 * @Date 2019/8/6 21:16
	 **/
	public static int age2Day(String age) {
		Calendar calendar = Calendar.getInstance();
		calendar.setTime(new Date());
		int ageNum = 0;
		//岁月周天
		if(age.contains("岁")){
			ageNum = Integer.parseInt(age.substring(0,age.indexOf("岁")));
			calendar.add(Calendar.YEAR,-ageNum);
			if(age.contains("月")){
				ageNum = Integer.parseInt(age.substring(age.indexOf("岁") + 1,age.indexOf("月")));
				calendar.add(Calendar.MONTH,-ageNum);
				if(age.contains("周")){
					ageNum = Integer.parseInt(age.substring(age.indexOf("月") + 1,age.indexOf("周")));
					calendar.add(Calendar.WEEK_OF_YEAR,-ageNum);
					if(age.contains("天")){
						ageNum = Integer.parseInt(age.substring(age.indexOf("周") + 1,age.indexOf("天")));
						calendar.add(Calendar.DATE,-ageNum);
					}
				}else if(age.contains("天")){
					ageNum = Integer.parseInt(age.substring(age.indexOf("月") + 1,age.indexOf("天")));
					calendar.add(Calendar.DATE,-ageNum);
				}

			}else if(age.contains("周")){
				ageNum = Integer.parseInt(age.substring(age.indexOf("岁") + 1,age.indexOf("周")));
				calendar.add(Calendar.WEEK_OF_YEAR,-ageNum);
				if(age.contains("天")){
					ageNum = Integer.parseInt(age.substring(age.indexOf("周") + 1,age.indexOf("天")));
					calendar.add(Calendar.DATE,-ageNum);
				}

			}else if(age.contains("天")){
				ageNum = Integer.parseInt(age.substring(age.indexOf("岁") + 1,age.indexOf("天")));
				calendar.add(Calendar.DATE,-ageNum);
			}
		}
		//月周天
		else if(age.contains("月")){
			ageNum = Integer.parseInt(age.substring(0,age.indexOf("月")));
			calendar.add(Calendar.MONTH,-ageNum);
			if(age.contains("周")){
				ageNum = Integer.parseInt(age.substring(age.indexOf("月") + 1,age.indexOf("周")));
				calendar.add(Calendar.WEEK_OF_YEAR,-ageNum);
				if(age.contains("天")){
					ageNum = Integer.parseInt(age.substring(age.indexOf("周") + 1,age.indexOf("天")));
					calendar.add(Calendar.DATE,-ageNum);
				}
			}else if(age.contains("天")){
				ageNum = Integer.parseInt(age.substring(age.indexOf("月") + 1,age.indexOf("天")));
				calendar.add(Calendar.DATE,-ageNum);
			}
		}
		//周天
		else if(age.contains("周")){
			ageNum = Integer.parseInt(age.substring(0,age.indexOf("周")));
			calendar.add(Calendar.WEEK_OF_YEAR,-ageNum);
			if(age.contains("天")){
				ageNum = Integer.parseInt(age.substring(age.indexOf("周") + 1,age.indexOf("天")));
				calendar.add(Calendar.DATE,-ageNum);
			}
		}
		//天
		else if(age.contains("天")){
			ageNum = Integer.parseInt(age.substring(0,age.indexOf("天")));
			calendar.add(Calendar.DATE,-ageNum);
		}

		String dateStr = new SimpleDateFormat("yyyy-MM-dd").format(calendar.getTime());
		return StringUtils.isNotBlank(dateStr) ? DateUtil.getBirthDays(dateStr) : 0;
	}
	
	  /**
     * 获取当前时间延缓几分钟后的时间
     * @param dateString HH:mm:ss
     * @param s 秒
     * @return 格式：HH:mm:ss
     */
    public static String addSeconds(String dateString, int s) {
        try {
            Date date = new SimpleDateFormat("HH:mm:ss").parse(dateString);
            Calendar c = Calendar.getInstance();
            c.setTime(date);
            c.add(Calendar.SECOND, s);
            return new SimpleDateFormat("HH:mm:ss").format(c.getTime());
        } catch (Exception e) {
            e.printStackTrace();
        }
        return "";
    }
}
